package com.xsqf.jt808.common.vo.resp;

import com.xsqf.jt808.common.util.BCD;
import com.xsqf.jt808.common.vo.DataPacket;
import io.netty.buffer.ByteBuf;
import lombok.Data;

/**
 * PositionReply
 * 位置信息查询应答
 *
 * @author
 * @date 2020/5/27 17:17
 */
@Data
public class PositionReply extends DataPacket {

    public PositionReply(ByteBuf byteBuf) {
        super(byteBuf);
    }

    private short repFlowId;//应答流水号
    private int alarm; //警告信息 4字节
    private int statusField;//状态 4字节
    private long latitude;//纬度 4字节
    private long longitude;//经度 4字节
    private short elevation;//海拔高度 2字节
    private short speed; //速度 2字节
    private short direction; //方向 2字节
    private String time; //时间 6字节BCD

    @Override
    public void parseBody() {
        ByteBuf bb = this.payload;
        this.setRepFlowId(bb.readShort());
        this.setAlarm(bb.readInt());
        this.setStatusField(bb.readInt());
        this.setLatitude(bb.readUnsignedInt());
        this.setLongitude(bb.readUnsignedInt());
        this.setElevation(bb.readShort());
        this.setSpeed(bb.readShort());
        this.setDirection(bb.readShort());
        this.setTime(BCD.toBcdTimeString(readBytes(6)));
    }
}
